Add \ion, \positiveion, \negativeion commands for chemistry notation#45
Add \ion, \positiveion, \negativeion commands for chemistry notation#45drdrew42 wants to merge 1 commit into
Conversation
Ion charge notation — `\ion[+]{2}` rendering the "2+" of a 2+ cation — is a superscript-only command: an editable charge block followed by a fixed sign. `\positiveion` and `\negativeion` are sign-bound shorthands.
These commands existed in a downstream MathQuill fork used for WeBWorK chemistry problems (the chemQuill answer-entry toolbars); this restores them on @openwebwork/mathquill so that work can drop the private fork.
Ion extends SupSub, mirroring the existing subscript/superscript classes. latex() serializes to \ion[sign]{charge}; \positiveion / \negativeion canonicalize to the same. Round-trip tests added to test/latex.test.ts.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
I think you need to add some explanation of how to use this, and how this would work with PG. This isn't something that can be directly typed into a MathQuill input. |
|
Originally, LibreTexts wanted to implement a toolbar for chemistry problems (see repo for foundations), and looped in Davide to help improve contextReaction.pl (which includes implementation of ions, compatible with this extension of MathQuill)... and some of that work has now been folded into PG official. They're finally pulled up to date with PG, but that migration has hit a snag -- as it seems I never submitted the ions implementation to our fork of MathQuill. Ions are not "real" LaTeX, and it is unexpected that any student would type them in (though they could...), rather it is expected that mathquill toolbar entries be added for them (LibreTexts has macros for this already): I have a similar request to add a |
What
Adds three LaTeX commands for chemistry ion-charge notation:
\ion[sign]{charge}— a superscript-only command: an editable charge block followed by a fixed+/-sign, rendering e.g. the "2+" of a 2+ cation.\positiveion/\negativeion— sign-bound shorthands that canonicalize to\ion[+]{…}/\ion[-]{…}.Why
These commands existed in a downstream MathQuill fork used for WeBWorK chemistry problems — the chemistry answer-entry toolbars drive
\positiveion/\negativeionfor entering ion charges. They were lost when that work moved onto@openwebwork/mathquill, silently breaking those toolbar buttons. Restoring them upstream lets the downstream work drop the private fork.How
IonextendsSupSub, mirroring the existing subscript/superscript classes incommands.ts—supsub = 'sup', anhtmlTemplatecarrying the editable charge block plus a.mq-ion-classed sign span, and aparser()built onlatexMathParser.optBlock/.blockexactly likeNthRoot.latex()serializes to\ion[sign]{charge}; an absent optional sign defaults to+, and an empty charge block to1..mq-ionis a styling hook on the sign span — no CSS rule is added; it renders correctly with the existingmq-supstyles.Testing
npm run build,npm run lint:check, andnpm run format:checkall pass.test/latex.test.ts(theion chargestest), following the existingassertParsesLatexpattern.🤖 Generated with Claude Code